import request from "@/utils/request";

//基础销售属性的某一个类型
export interface BaseSaleAttrItemType {
  id?: number;
  name: string;
}
//基础销售属性列表的类型
export type BaseSaleAttrListType = BaseSaleAttrItemType[];

//spu图片列表的某一项类型
export interface SpuImageItemType {
  id?: number;
  imgName: string;
  imgUrl: string;
  spuId?: number;
  name?: string;
  url?: string;
}
//spu图片列表的类型
export type SpuImageListType = SpuImageItemType[];

//spu销售属性值的列表中某一项的类型
export interface SpuSaleAttrValueItemType {
  baseSaleAttrId?: number;
  id?: number;
  isChecked?: string;
  saleAttrName: string;
  saleAttrValueName: string;
  spuId?: number;
}
//spu销售属性值列表的数据类型
export type SpuSaleAttrValueListType = SpuSaleAttrValueItemType[];

//某个spu的销售属性列表中的某一项类型
export interface SpuSaleAttrItemType {
  baseSaleAttrId?: number;
  id?: number;
  saleAttrName: string;
  spuId?: number;
  spuSaleAttrValueList: SpuSaleAttrValueListType;
  isEdit?: boolean,
  inputValue?: string
}
//spu销售属性列表类型
export type SpuSaleAttrListType = SpuSaleAttrItemType[];

//一个完整的spu信息的类型
export interface SpuInfoType {
  category3Id: number | null;
  description: string;
  id?: number;
  spuName: string;
  tmId?: number | null;
  spuImageList: SpuImageListType | null;
  spuSaleAttrList: SpuSaleAttrListType | null;
}

//Spu分页列表数据类型
export interface SpuListType {
  total: number;
  size: number;
  current: number;
  searchCount: boolean;
  pages: number;
  records: SpuInfoType[];
}

//1.请求spu所有销售属性列表
export const requestBaseSaleAttrList = () => {
  return request.get<any, BaseSaleAttrListType>(
    `/admin/product/baseSaleAttrList`
  );
};

//2.根据spuId删除spu
export const requestDeleteSpu = (spuId: number) => {
  return request.delete<any, null>(`/admin/product/deleteSpu/${spuId}`);
};

//3.新增Spu
export const requestSaveSpuInfo = (spuInfo: SpuInfoType) => {
  return request.post<any, null>(`/admin/product/saveSpuInfo`, spuInfo);
};

//4.更新Spu
export const requestUpdateSpuInfo = (spuInfo: SpuInfoType) => {
  return request.post<any, null>(`/admin/product/updateSpuInfo`, spuInfo);
};

//5.获取spu的分页列表
export const requestSpuList = (
  page: number,
  limit: number,
  category3Id: number
) => {
  return request.get<any, SpuListType>(
    `/admin/product/${page}/${limit}?category3Id=${category3Id}`
  );
};

//6.根据spuId获取Spu图片列表
export const requestSpuImgList = (spuId: number) => {
  return request.get<any, SpuImageListType>(
    `/admin/product/spuImageList/${spuId}`
  );
};

//7.根据spuId获取当前Spu的销售属性
export const requestSpuSaleAttrList = (spuId: number) => {
  return request.get<any, SpuSaleAttrListType>(
    `/admin/product/spuSaleAttrList/${spuId}`
  );
};
